from urllib.request import urlretrieve
import queue  
import threading   
import random
import time
class download(threading.Thread):  
    def __init__(self,que,name):  
        threading.Thread.__init__(self)  
        self.que=que  
        self.name = name
    def run(self):  
        while True:  
            if not self.que.empty():   
                host=self.que.get()
                urlretrieve(host,'Test3/m4d/%s.m4a'%str(self.name)) 
            else:   
                break  
  
def Down():  
    f=open('Test3/m4d/m4a.txt','r')
    a=f.readlines()
    f.close()
    que=queue.Queue() 
    threads=[]
    for i in a:  
        que.put(i.replace('\n',''))  

    for i in range(len(a)):  
        d=download(que,i) 
        threads.append(d)
    for i in threads:
        i.start()
    for i in threads:
        i.join()
  
if __name__=='__main__':   
    start=time.time()
    Down()  
    end=time.time()
    print(end-start)
